package com.imay.live.view.custom;

/**
 * Created by Administrator on 2017/04/28 0028.
 */


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.imay.live.R;

/**
 * 到账金额
 */
public class MoneyTextView extends LinearLayout {
    private Paint paint;
    private Path path;
    TextView textmoney;
    String money;
    ImageView imageView;

    public MoneyTextView(Context context) {
        super(context);
        init(context);
    }

    @Override
    protected void dispatchDraw(Canvas canvas) {
        super.dispatchDraw(canvas);
        if (path == null) {
            path = new Path();
            paint = new Paint();
            paint.setStyle(Paint.Style.STROKE);
            paint.setAntiAlias(true);
            paint.setStrokeWidth(4);
            paint.setColor(getResources().getColor(R.color.divider_f0));
        }
        path.reset();
        path.moveTo(0, canvas.getHeight());
        path.lineTo(canvas.getWidth(), canvas.getHeight());
        canvas.drawPath(path, paint);
    }

    private void init(Context context) {
        setBackgroundColor(getResources().getColor(R.color.bg_window));
        TextView texttitle = new TextView(context);
        texttitle.setTextColor(getResources().getColor(R.color.text_00));
        LayoutParams titleparams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        titleparams.leftMargin = (int) getResources().getDimension(R.dimen.profitreallyname_top);
        titleparams.gravity = Gravity.CENTER_VERTICAL;
        addView(texttitle, titleparams);
        imageView = new ImageView(context);
        imageView.setImageResource(R.mipmap.icn_05_double);
        LayoutParams imgparams = new LayoutParams((int) (context.getResources().getDimension(R.dimen.item_double)), (int) (context.getResources().getDimension(R.dimen.item_double)));
        imgparams.gravity = Gravity.CENTER_VERTICAL;
        addView(imageView, imgparams);

        textmoney = new TextView(context);
        textmoney.setText("0.00" + getResources().getString(R.string.rmb));
        textmoney.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.recharge_tips_size));
        textmoney.setTextColor(getResources().getColor(R.color.text_4a));
        LayoutParams tipparams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        tipparams.weight = 1;
        tipparams.leftMargin = (int) getResources().getDimension(R.dimen.profitreallyname_top);
        tipparams.gravity = Gravity.CENTER_VERTICAL;
        addView(textmoney, tipparams);
        texttitle.setText(getResources().getString(R.string.profitgetmoney));

    }

    public void showDouble(boolean isdouble) {
        if (imageView != null) {
            if (isdouble) {
                imageView.setVisibility(VISIBLE);
            } else {
                imageView.setVisibility(GONE);
            }
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec((int) getResources().getDimension(R.dimen.profitreally_height), MeasureSpec.EXACTLY));
    }

    public void setText(String money) {
        this.money = money;
        textmoney.setText(money + getResources().getString(R.string.rmb));
    }

    public String getMoney() {
        return money;
    }
}
